using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace BookShop
{
	/// <summary>
	/// Strongly-typed collection for the Message class.
	/// </summary>
    [Serializable]
	public partial class MessageCollection : ActiveList<Message, MessageCollection>
	{	   
		public MessageCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>MessageCollection</returns>
		public MessageCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                Message o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the Message table.
	/// </summary>
	[Serializable]
	public partial class Message : ActiveRecord<Message>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public Message()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public Message(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public Message(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public Message(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("Message", TableType.Table, DataService.GetInstance("BookShop"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarMsgID = new TableSchema.TableColumn(schema);
				colvarMsgID.ColumnName = "MsgID";
				colvarMsgID.DataType = DbType.Int32;
				colvarMsgID.MaxLength = 0;
				colvarMsgID.AutoIncrement = true;
				colvarMsgID.IsNullable = false;
				colvarMsgID.IsPrimaryKey = true;
				colvarMsgID.IsForeignKey = false;
				colvarMsgID.IsReadOnly = false;
				colvarMsgID.DefaultSetting = @"";
				colvarMsgID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarMsgID);
				
				TableSchema.TableColumn colvarTitle = new TableSchema.TableColumn(schema);
				colvarTitle.ColumnName = "Title";
				colvarTitle.DataType = DbType.String;
				colvarTitle.MaxLength = 50;
				colvarTitle.AutoIncrement = false;
				colvarTitle.IsNullable = true;
				colvarTitle.IsPrimaryKey = false;
				colvarTitle.IsForeignKey = false;
				colvarTitle.IsReadOnly = false;
				colvarTitle.DefaultSetting = @"";
				colvarTitle.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTitle);
				
				TableSchema.TableColumn colvarReceiver = new TableSchema.TableColumn(schema);
				colvarReceiver.ColumnName = "Receiver";
				colvarReceiver.DataType = DbType.AnsiStringFixedLength;
				colvarReceiver.MaxLength = 10;
				colvarReceiver.AutoIncrement = false;
				colvarReceiver.IsNullable = true;
				colvarReceiver.IsPrimaryKey = false;
				colvarReceiver.IsForeignKey = false;
				colvarReceiver.IsReadOnly = false;
				colvarReceiver.DefaultSetting = @"";
				colvarReceiver.ForeignKeyTableName = "";
				schema.Columns.Add(colvarReceiver);
				
				TableSchema.TableColumn colvarSender = new TableSchema.TableColumn(schema);
				colvarSender.ColumnName = "Sender";
				colvarSender.DataType = DbType.AnsiStringFixedLength;
				colvarSender.MaxLength = 10;
				colvarSender.AutoIncrement = false;
				colvarSender.IsNullable = true;
				colvarSender.IsPrimaryKey = false;
				colvarSender.IsForeignKey = false;
				colvarSender.IsReadOnly = false;
				colvarSender.DefaultSetting = @"";
				colvarSender.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSender);
				
				TableSchema.TableColumn colvarStatus = new TableSchema.TableColumn(schema);
				colvarStatus.ColumnName = "Status";
				colvarStatus.DataType = DbType.AnsiStringFixedLength;
				colvarStatus.MaxLength = 10;
				colvarStatus.AutoIncrement = false;
				colvarStatus.IsNullable = true;
				colvarStatus.IsPrimaryKey = false;
				colvarStatus.IsForeignKey = false;
				colvarStatus.IsReadOnly = false;
				colvarStatus.DefaultSetting = @"";
				colvarStatus.ForeignKeyTableName = "";
				schema.Columns.Add(colvarStatus);
				
				TableSchema.TableColumn colvarSource = new TableSchema.TableColumn(schema);
				colvarSource.ColumnName = "Source";
				colvarSource.DataType = DbType.AnsiString;
				colvarSource.MaxLength = 50;
				colvarSource.AutoIncrement = false;
				colvarSource.IsNullable = true;
				colvarSource.IsPrimaryKey = false;
				colvarSource.IsForeignKey = false;
				colvarSource.IsReadOnly = false;
				colvarSource.DefaultSetting = @"";
				colvarSource.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSource);
				
				TableSchema.TableColumn colvarSendDate = new TableSchema.TableColumn(schema);
				colvarSendDate.ColumnName = "SendDate";
				colvarSendDate.DataType = DbType.DateTime;
				colvarSendDate.MaxLength = 0;
				colvarSendDate.AutoIncrement = false;
				colvarSendDate.IsNullable = true;
				colvarSendDate.IsPrimaryKey = false;
				colvarSendDate.IsForeignKey = false;
				colvarSendDate.IsReadOnly = false;
				
						colvarSendDate.DefaultSetting = @"(getdate())";
				colvarSendDate.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSendDate);
				
				TableSchema.TableColumn colvarType = new TableSchema.TableColumn(schema);
				colvarType.ColumnName = "Type";
				colvarType.DataType = DbType.AnsiStringFixedLength;
				colvarType.MaxLength = 20;
				colvarType.AutoIncrement = false;
				colvarType.IsNullable = true;
				colvarType.IsPrimaryKey = false;
				colvarType.IsForeignKey = false;
				colvarType.IsReadOnly = false;
				colvarType.DefaultSetting = @"";
				colvarType.ForeignKeyTableName = "";
				schema.Columns.Add(colvarType);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["BookShop"].AddSchema("Message",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("MsgID")]
		[Bindable(true)]
		public int MsgID 
		{
			get { return GetColumnValue<int>(Columns.MsgID); }
			set { SetColumnValue(Columns.MsgID, value); }
		}
		  
		[XmlAttribute("Title")]
		[Bindable(true)]
		public string Title 
		{
			get { return GetColumnValue<string>(Columns.Title); }
			set { SetColumnValue(Columns.Title, value); }
		}
		  
		[XmlAttribute("Receiver")]
		[Bindable(true)]
		public string Receiver 
		{
			get { return GetColumnValue<string>(Columns.Receiver); }
			set { SetColumnValue(Columns.Receiver, value); }
		}
		  
		[XmlAttribute("Sender")]
		[Bindable(true)]
		public string Sender 
		{
			get { return GetColumnValue<string>(Columns.Sender); }
			set { SetColumnValue(Columns.Sender, value); }
		}
		  
		[XmlAttribute("Status")]
		[Bindable(true)]
		public string Status 
		{
			get { return GetColumnValue<string>(Columns.Status); }
			set { SetColumnValue(Columns.Status, value); }
		}
		  
		[XmlAttribute("Source")]
		[Bindable(true)]
		public string Source 
		{
			get { return GetColumnValue<string>(Columns.Source); }
			set { SetColumnValue(Columns.Source, value); }
		}
		  
		[XmlAttribute("SendDate")]
		[Bindable(true)]
		public DateTime? SendDate 
		{
			get { return GetColumnValue<DateTime?>(Columns.SendDate); }
			set { SetColumnValue(Columns.SendDate, value); }
		}
		  
		[XmlAttribute("Type")]
		[Bindable(true)]
		public string Type 
		{
			get { return GetColumnValue<string>(Columns.Type); }
			set { SetColumnValue(Columns.Type, value); }
		}
		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(string varTitle,string varReceiver,string varSender,string varStatus,string varSource,DateTime? varSendDate,string varType)
		{
			Message item = new Message();
			
			item.Title = varTitle;
			
			item.Receiver = varReceiver;
			
			item.Sender = varSender;
			
			item.Status = varStatus;
			
			item.Source = varSource;
			
			item.SendDate = varSendDate;
			
			item.Type = varType;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varMsgID,string varTitle,string varReceiver,string varSender,string varStatus,string varSource,DateTime? varSendDate,string varType)
		{
			Message item = new Message();
			
				item.MsgID = varMsgID;
			
				item.Title = varTitle;
			
				item.Receiver = varReceiver;
			
				item.Sender = varSender;
			
				item.Status = varStatus;
			
				item.Source = varSource;
			
				item.SendDate = varSendDate;
			
				item.Type = varType;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn MsgIDColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn TitleColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn ReceiverColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn SenderColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn StatusColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn SourceColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        public static TableSchema.TableColumn SendDateColumn
        {
            get { return Schema.Columns[6]; }
        }
        
        
        
        public static TableSchema.TableColumn TypeColumn
        {
            get { return Schema.Columns[7]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string MsgID = @"MsgID";
			 public static string Title = @"Title";
			 public static string Receiver = @"Receiver";
			 public static string Sender = @"Sender";
			 public static string Status = @"Status";
			 public static string Source = @"Source";
			 public static string SendDate = @"SendDate";
			 public static string Type = @"Type";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
